import { createApp } from "vue";
import pinia from "./stores";
import ElementPlus from "element-plus";
import zhCn from "element-plus/es/locale/lang/zh-cn";
import "element-plus/dist/index.css";
import App from "./App.vue";
import router from "./router";
import "./styles/index.scss";
import ElSvg from "./components/SvgIcon/ElSvg";
import "./permission";
import Category from "@/components/Category/index.vue";
import CommonCard from "@/views/home/components/CommonCard.vue";
import { vueEcharts } from "@/plugins/echarts";
import { useUserInfoStore } from "@/stores/userInfo";

//引入mock
import "@/mockServer";

const app = createApp(App);
const userInfoStore = useUserInfoStore(pinia);
ElSvg(app);
//全局注册组件categroy
app.component("Category", Category);
app.component("CommonCard", CommonCard);

// 注册自定义指令
app.directive("has", (el, bing) => {
  //el是该按钮元素 bing是当前自定义指令的值
  if (!userInfoStore.userInfo.buttons.includes(bing.value)) {
    //如果该值在请求返回值的buttons不存在的话就删除
    el.remove();
  }
});

app
  .use(pinia)
  .use(router)
  .use(vueEcharts)
  .use(ElementPlus, {
    locale: zhCn,
  })
  .mount("#app");
